package com.iemes.controller.transport;


import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iemes.annotation.SystemLog;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.TransportNofullcarFormMap;
import com.iemes.mapper.transport.TransportNofullcarMapper;
import com.iemes.plugin.PageView;
import com.iemes.util.Common;

@RequestMapping("/transportNofullcar/")
@Controller
public class TransportNofullcarController extends BaseController{
	@Inject
	private TransportNofullcarMapper transportNofullcarMapper;
	
	//不满车产品出货
		@RequestMapping("/examinetransportNofullcar")
		public String examineTransport(Model model){
			model.addAttribute("res", findByRes());
			return Common.BACKGROUND_PATH+"/transport/nofullcar/transportNofullcar_list";
		}
		@ResponseBody
		@RequestMapping("/transportNofullcar_findbyPage")
		public PageView findByPage(String pageNow, String pageSize) throws Exception 
		{
			TransportNofullcarFormMap transportNofullcarFormMap=getFormMap(TransportNofullcarFormMap.class);
			List<Map<String, Object>> transportNofullcarFormMaps = transportNofullcarMapper.getAllInfo(transportNofullcarFormMap);
			for (Map<String, Object> map : transportNofullcarFormMaps) {
				
				transportNofullcarFormMap.put("permitNumber", map.get("permitNumber"));
				transportNofullcarFormMap.put("licenseNo", map.get("licenseNo"));
				transportNofullcarFormMap.put("category", map.get("category"));
				transportNofullcarFormMap.put("consent", map.get("consent"));
				transportNofullcarFormMap.put("name", map.get("name"));
				
				map.put("category",map.get("category"));
				if (Integer.valueOf(map.get("category").toString())==1) {
					map.put("category", "物料编码");
				}else if (Integer.valueOf(map.get("category").toString())==2){
					map.put("category", "模具编号");
				}
				
				map.put("consent",map.get("consent"));
				if (Integer.valueOf(map.get("consent").toString())==1) {
					map.put("consent", "同意");
				}else if(Integer.valueOf(map.get("consent").toString())==2){
					map.put("consent", "不同意");
				}
			}
			LuogicPaging(pageNow, pageSize, transportNofullcarFormMaps);
			return pageView;
		}
		//删除不满车产品出货
		@ResponseBody
		@RequestMapping("transportNofullcar_deleteEntity")
		@Transactional(readOnly=false)//需要事务操作必须加入此注解
		@SystemLog(module="删除不满车产品出货",methods="pod按钮-删除pod按钮")//凡需要处理业务逻辑的.都需要记录操作日志
		public String deleteEntity() throws Exception {
			TransportNofullcarFormMap transportNofullcarFormMap=getFormMap(TransportNofullcarFormMap.class);
			String[] ids = getParaValues("ids");
			String arr=ids[0];
			String[] str=arr.split(",");
			for(int i=0;i<str.length;i++){
				transportNofullcarFormMap.set("status", 2);
				transportNofullcarFormMap.put("id", str[i]);
				transportNofullcarMapper.editEntity(transportNofullcarFormMap);
			}
			
			return "success";
		}
}
